package com.zebra.robot.common;

import com.zebra.common.ZebraBaseMessage;
import com.zebra.gateway.protocol.GatewayCommand;
import io.netty.channel.Channel;

public class SendMessageUtil {

    public static void sendMessage(Channel ctx, GatewayCommand msg){
        msg.getMsgBuf().release();
        msg.messageEncoder();
        ctx.writeAndFlush(msg);
    }

    public static void sendMessage(Channel channel, long userId, long tk, int cmd, ZebraBaseMessage message){
        GatewayCommand command =buildCommand(userId, tk, cmd, message);
        channel.writeAndFlush(command);
    }

    public static GatewayCommand buildCommand(long userId, long tk, int cmd, ZebraBaseMessage message){
        GatewayCommand command = new GatewayCommand();
        command.setUserId(userId);
        command.setToken(tk);
        command.setCmd(cmd);
        command.setMessage(message);
        command.messageEncoder();
        return command;
    }
}
